import java.security.PublicKey;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

//炉石传说
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();//操作数量
        sc.nextLine();//换行？？？？？
        int playercount = 2;//控制玩家的回合分辨先手和后手玩家
        Game game = new Game();
        for (int i = 0; i < n; i++) {
            String command = sc.nextLine();//输入我要执行的三条指令
            if (command.equals("end")) {
                //若该指令为end，则直接结束回合
                playercount++;//表示要进入后手回合
            } else if (command.contains("summon")) {
                //若该指令为summon，则召唤随从
                //summon <position> <attack> <health>
                String[] strs = command.split(" ");
                Follower follower = new Follower(Integer.parseInt(strs[3]), Integer.parseInt(strs[2]));
                game.players[playercount % 2].summonFollower(Integer.parseInt(strs[1]), follower);
            } else {
                //攻击
                //attack <attacker> <defender>:
                String[] strs = command.split(" ");
                int a = playercount % 2;
                int b = (a == 0 ? 1 : 0);
                game.players[a].attack(Integer.parseInt(strs[1]), Integer.parseInt(strs[2]), game.players[b]);
            }
        }
        game.outputResult();
    }
}

//游戏类
class Game {
    public Player[] players = new Player[2];//创建一个能够储存两个玩家的空间
    public int endCode = 0;//1表示先手玩家赢了 -1表示后手 0表示还没游戏结束

    public Game() {
        players[0] = new Player(1, this);
        players[1] = new Player(-1, this);
    }

    //输出
    public void outputResult() {
        System.out.println(endCode);
        //输出先手的情况
        System.out.println(players[0].heroBlood);
        System.out.println(players[0].followers.size());
        for (int i = 1; i <= 7; i++) {
            Follower follower = players[0].followers.get(i);
            if(follower==null){
                break;
            }else{
                System.out.print(" "+follower.blood);
            }
        }
        System.out.println();

        //输出后手的情况
        System.out.println(players[1].heroBlood);
        System.out.println(players[1].followers.size());
        for (int i = 1; i <= 7; i++) {
            Follower follower = players[1].followers.get(i);
            if(follower==null){
                break;
            }else{
                System.out.print(" "+follower.blood);
            }
        }
    }
}

//玩家类
class Player {
    public int heroBlood = 30;
    public int code;
    public Game game;
    public Map<Integer, Follower> followers = new HashMap<>();

    public Player(int code, Game game) {
        this.code = code;
        this.game = game;
    }

    public void summonFollower(int place, Follower follower) {
        Follower fo = followers.get(place);//临时随从fo用于储存相应位置的随从
        //如果当前位置已经被占用 那么需要把右边的位置都加1
        if (fo != null) {
            int a = followers.size();
            for (int i = a; i >= place; i--) {
                //从后往前修改
                Follower fol = followers.get(i);//真临时随从
                followers.remove(i);
                followers.put(i + 1, fol);
            }
        }
        followers.put(place, follower);
    }

    //攻击
    public void attack(int myFollower, int enemyFoller, Player enemy) {
        Follower my = followers.get(myFollower);//我的随从
        if (enemyFoller == 0) {
            //如果攻击的是英雄
            enemy.heroBlood -= my.attack;
            //判断一下游戏是否结束
            boolean isGameOver = enemy.isGameOver();
            if (isGameOver) {
                game.endCode = this.code;
            } else {
                //如果攻击的是小兵
                Follower enem = enemy.followers.get(enemyFoller);//临时储存敌方随从
                my.blood = my.blood - enem.attack;
                enem.blood = enem.blood - my.attack;
                updateBattleFiledAfterAttack(myFollower);
            }
        }
    }

    //如果攻击后随从死亡 需要更新战场
    public void updateBattleFiledAfterAttack(int place) {
        Follower f = followers.get(place);
        if (f.blood <= 0) {
            followers.remove(place);
            if (followers.get(place + 1) == null) {
                //如果当前死亡的是最后一个不需要更新序号
                return;
            } else if (place == 1 && followers.size() >= 1) {
                //如果死的是第一个随从且随从不止一个
                for (int i = 2; i <= followers.size() + 1; i++) {
                    Follower follower = followers.get(i);
                    followers.remove(i);
                    followers.put(i - 1, follower);
                }
            } else {
                for (int i = place - 1; i >= 1; i--) {
                    Follower ff = followers.get(i);
                    if (ff != null) {
                        followers.remove(i);
                        followers.put(i + 1, ff);
                    }
                }
            }
        }
    }

    //判断游戏是否结束
    public boolean isGameOver() {
        return heroBlood <= 0 ? true : false;
    }
}

//随从类
class Follower {
    public int blood = 0;
    public int attack = 0;

    public Follower(int blood, int attack) {
        this.blood = blood;
        this.attack = attack;
    }
}
